/**
 * 运维中心服务状态管理controller层
 */
import request from '@/utils/request'
import service from '@/api/config/const'
import { paramToString } from '@/utils/param'
/**
 * 根据服务名称模糊获取服务
 * @param appName
 * @returns {V|*}
 */
export function getByAppName(appName) {
  return request.get(service.register_center + '/restful/eureka/apps/cluster/' + appName)
}

/**
 * 获取所有服务的详细信息
 * @returns {V|*}
 */
export function getAll() {
  return request.get(service.register_center + '/restful/eureka/appsInfo')
}

/**
 * 根据id模糊获取信息
 * @param id
 */
export function getById(id) {
  const data = {
    id
  }
  return request.post(service.register_center + '/restful/eureka/apps', paramToString(data))
}

/**
 * 根据id和appName精确查询信息
 * @param appName
 * @param id
 * @returns {V|*}
 */
export function getByIdAndAppName(appName, id) {
  const data = {
    appName,
    id
  }
  return request.post(service.register_center + '/restful/eureka/apps/app', paramToString(data))
}

/**
 * 调整服务的状态,默认是全部传播
 * @param appName
 * @param id
 * @param status
 * @returns {*}
 */
export function updateService(appName, id, status) {
  const data = {
    appName,
    id,
    status,
    isReplication: false
  }
  return request.put(service.register_center + '/restful/eureka', paramToString(data))
}
